$server = 'http://localhost:8080/';

window.onload = function(){
	$keyword = GetQueryString("keyword");
	$categoryId = GetQueryString("categoryId");
	$.ajax({
		type: "POST",
		url: $server+'commodity/search.do',
		data: {keyword: $keyword, categoryId: $categoryId},
		crossDomain:true, //设置跨域为true
		xhrFields:{
			withCredentials: true // 携带跨域cookie
		},
		success: function(result){
			console.log(result);
			if (result.code == 200){
				$htmlstr = '';
				$.each(result.data.list, function(index, value){
					$htmlstr += '' +
					'<div class="content">' +
					    '<div class="img_box">' +
					        '<a href="javascript:void(0);" onclick=cmClick(this) data-id='+value.id+'>' +
					            '<img src="img/Listpage/Basketball_1.jpg" alt=""/>' +
					        '</a>' +
					    '</div>' +
					    '<div class="introduce">' +
					        value.name +
					    '</div>' +
					    '<div class="price">' +
					        // '<del class="old_price">￥310</del>' +
					        '<span>￥</span>' +
					        '<span class="new_price">'+value.price+'</span>' +
					    '</div>' +
					    '<div class="add_content">' +
					        '<span class="contrast">对比</span>' +
					        '<div class="com1">' +
					            '<div class="com"><span>0</span>评,</div>' +
					            '<span><span>0</span>问</span>' +
					            '<span class="new">新品</span>' +
					        '</div>' +
					    '</div>' +
					'</div>';
				});
				$('.main_main').html($htmlstr);
			}else{
				// alert(result.msg);
			}
		}
	});
}

// 从地址栏获取参数
function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = decodeURI(window.location.search.substr(1)).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}

// 点击商品跳转
function cmClick(obj){
	$id = $(obj).attr('data-id');
	window.open(encodeURI('commodityDetail.html?id='+$id));
}

$(function () {
 var isT = false;
 //底部换一换
    $('.like_right').click(function () {
        isT?$('.like_img').css({'marginLeft': '-1235px',transition:'2s'}):$('.like_img').css({'marginLeft': '0px',transition:'2s'});
        isT =!isT;
    });
    mengbang($('.content,.like_img1'),$('.img_box a img,.like_img1 div a img'));
});
